Quasiquote

T's quasiquote facility, inherited from the Maclisp family of Lisps, is useful for building programs whose form is determined, but where some of the structure is constant and some is to be filled in. This is especially convenient in the definitions of macro expanders. It is so useful that a special external syntax is provided for notating such templates. It takes its name from the name of the character (quasiquote, ` ) which introduces this special syntax.

The character ("` ") is called quasiquote because it behaves like QUOTE except that one can specify that subforms of the quasiquote'd form should be evaluated. Inside a form that is preceded by a quasiquote, two additional pieces of external syntax are active: comma (,), and comma at-sign (,@); these are the ways to indicate that some subform should be evaluated (i.e., unquoted). A subform preceded by a comma is evaluated and replaced by the result of the evaluation. A subform preceded by a comma at-sign is evaluated and replaced by splicing in the result of the evaluation.

Here are some simple examples. Note that the first example shows code equivalence, not evaluation.
\begin{codexenv}
\begin{tabular}{lll}
\lq  (A B ,X Y) &$\equiv$& (LIST 'A 'B X 'Y)...
...
(CDR \lq  (A B ,@X C)) &$\Longrightarrow$\ & (B 3 C)
\end{tabular} \end{codexenv}


(DEFINE-SYNTAX (REPEAT N . CODE)     ;Execute CODE N times  

` (LET ((COUNT ,N) (THUNK (LAMBDA () ,@CODE)))
(DO ((COUNT COUNT (-1+ COUNT)))
((<=0? COUNT) '())
(THUNK))))

It is possible to nest quasiquoted forms. This is useful when writing complex source-to-source transformations.


(DEFINE-SYNTAX (FOO X Y)  

` (LET ((STUFF ,X))
` ((STUFF-IS ,STUFF)
(Y-IS ,',Y))))

(FOO (+ 3 5) BAZ) $\Longrightarrow$ ((STUFF-IS 8) (Y-IS BAZ))

quasiquote now works on vectors. Thus,
\begin{codexenv}
\lq  \char93 (1 2 ,(+ 1 2)) $\Longrightarrow$\ \char93 (1 2 3)
\end{codexenv}